package com.cg.mapper;

import com.cg.entity.Events;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EventsMapper {
    List<Events> eventsList(@Param("userId")Integer userId,@Param("categoryId") Integer categoryId,@Param("title") String title,@Param("priority") Integer priority,@Param("status") Integer status);
    @Insert("insert into events (user_id, category_id, title, start_date, end_date, description, priority, status, created_at, updated_at) values (#{userId},#{categoryId},#{title},#{startDate},#{endDate},#{description},#{priority},#{status},now(),now())")
    void addevent(@Param("userId")Integer userId,@Param("title") String title,@Param("categoryId") Integer categoryId,@Param("startDate") String startDate,@Param("priority") Integer priority,@Param("endDate") String endDate,@Param("status") Integer status,@Param("description") String description);
    @Select("select * from events where event_id=#{eventId}")
    Events findEventById(Integer eventId);
    @Update("update events set title=#{title},category_id=#{categoryId},start_date=#{startDate},priority=#{priority},end_date=#{endDate},status=#{status},description=#{description},updated_at=now() where event_id=#{eventId}")
    void editEvent(@Param("title")String title ,@Param("categoryId")Integer categoryId,@Param("startDate") String startDate,@Param("priority") Integer priority,@Param("endDate") String endDate,@Param("status") Integer status,@Param("description") String description,@Param("eventId") Integer eventId);
    @Delete("delete from events where event_id=#{eventId}")
    void deleteEvent(Integer eventId);
    @Select("select count(*) from events where category_id=#{categoryId}")
    int findByCategoryId(Integer categoryId);
    @Select("select count(*) from events where title=#{title} and user_id=#{userId}")
    int findByTitle(@Param("title") String title,@Param("userId")Integer userId);
}
